/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mb.config;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author thanh.nguyenchi
 */
public class MonitorConfig {
    private int port;
    List<User> arrUser;
    
    public MonitorConfig(){
        arrUser = new ArrayList<User>();
    }

    /**
     * @return the port
     */
    public int getPort() {
        return port;
    }

    /**
     * @param port the port to set
     */
    public void setPort(int port) {
        this.port = port;
    }
    
    
    public void addListUser(String listIP,String listUser){
        String[] ip = listIP.split("\\,");
        String[] user = listUser.split("\\,");
        if (ip.length == user.length){
            for (int i=0;i<ip.length;i++){
                addUser(user[i],"",ip[i]);
            }
        }
    }
    
    public void addUser(String user,String pass,String ip){
        if (arrUser == null){
            arrUser = new ArrayList<User>();
        }
        User objUser = new User(user,pass,ip);
        arrUser.add(objUser);
    }
    
    public boolean isCheckIP(String ip){
        for(int i = 0; i < arrUser.size(); i++){
            User objUser = arrUser.get(i);
            if (objUser.ip.equals(ip)){
                return true;
            }            
        }        
        return false;
    }
    
    public int getUserSize(){
        return arrUser.size();
    }
    
    public boolean isCheckUserIP(String user,String ip){
        for(int i = 0; i < arrUser.size(); i++){
            User objUser = arrUser.get(i);
            if (objUser.ip.equals(ip) && (objUser.user.equals(user))){
                return true;
            }            
        }        
        return false;
    }
}

class User{
    String user;
    String pass;
    String ip;
    
    User(String user,String pass,String ip){
        this.ip = ip;
        this.user = user;
        this.pass = pass;
    }
}
